Skip to content

feat(java): conditional workflow steps#332

Merged
pratyush618 merged 5 commits into
masterfrom
feat/java-workflows-conditions
Jun 30, 2026
Merged

feat(java): conditional workflow steps#332
pratyush618 merged 5 commits into
masterfrom
feat/java-workflows-conditions

Conversation

@pratyush618

@pratyush618 pratyush618 commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Second PR in the Java-SDK full-parity series (stacked on #331).

Changes

  • Conditional workflow steps — a step can declare a condition that decides whether it runs from its predecessors' outcomes: on_success (default), on_failure, always, or a callable Condition evaluated on the worker. promoteSuccessors was reworked to run on both success and failure, evaluating each successor's condition (recovery steps run, others skip-cascade).
  • New Condition (functional) + WorkflowContext (completed-node results/statuses the predicate sees). Callable conditions are registered via trackWorkflows(workflow).

No new Rust core — condition plumbing shipped with the gates PR; this wires the tracker.

Tests

Conditional-step coverage added; ./gradlew build green (Gradle 9.6.1, JDK 17/21/22 locally).

Summary by CodeRabbit

  • New Features

    • Added conditional workflow steps with built-in selectors for success, failure, and always-run behavior, plus support for custom predicate-based (callable) conditions.
    • Introduced a workflow execution context passed into predicate conditions, including prior node results and statuses.
  • Bug Fixes

    • Improved deferred-step detection and native workflow submission so conditional steps are preserved and evaluated correctly.
    • Reworked successor-promotion/advancement logic to decide run vs. skip based on conditions and predecessor outcomes.
  • Tests

    • Added coverage for success/failure/always and callable condition scenarios.

Run a step only when its condition holds: on_success/on_failure/always
or a callable predicate over the run's results. The tracker evaluates
every successor on each outcome, running on-failure recovery branches
and skip-cascading the rest, replacing the blanket fail-fast cascade.
on_failure recovery, on_success skip, always, and callable conditions.
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3d0ab20e-e050-4c6d-98bf-f97fb060aaaa

📥 Commits

Reviewing files that changed from the base of the PR and between 871d32b and c461331.

📒 Files selected for processing (3)
  • sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java
  • sdks/java/src/main/java/org/byteveda/taskito/workflows/Step.java
  • sdks/java/src/main/java/org/byteveda/taskito/workflows/WorkflowTracker.java
🚧 Files skipped from review as they are similar to previous changes (3)
  • sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java
  • sdks/java/src/main/java/org/byteveda/taskito/workflows/Step.java
  • sdks/java/src/main/java/org/byteveda/taskito/workflows/WorkflowTracker.java

📝 Walkthrough

Walkthrough

Adds conditional workflow step execution with selector-based and callable predicates. New public workflow context and condition types are wired through step modeling, submission serialization, tracker evaluation, and integration tests.

Changes

Workflow Conditional Execution

Layer / File(s) Summary
Condition interface and WorkflowContext record
sdks/java/src/main/java/org/byteveda/taskito/workflows/Condition.java, sdks/java/src/main/java/org/byteveda/taskito/workflows/WorkflowContext.java
Defines the Condition predicate interface and the WorkflowContext record with run id, node results, node statuses, and settled-node counters.
Step builder conditional API and PlanNode deserialization
sdks/java/src/main/java/org/byteveda/taskito/workflows/Step.java, sdks/java/src/main/java/org/byteveda/taskito/workflows/PlanNode.java
Adds conditional fields to Step, builder methods for onSuccess(), onFailure(), always(), and condition(Condition), and deserializes condition on PlanNode.
DefaultTaskito: conditional node serialization and deferral
sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java
Includes conditional steps in deferred-node detection and writes condition into serialized step specs.
WorkflowTracker: callable registry, promotion, and condition evaluation
sdks/java/src/main/java/org/byteveda/taskito/workflows/WorkflowTracker.java
Registers callable predicates, evaluates step conditions during successor promotion, builds workflow context for callable checks, and handles skip/run decisions from node state.
WorkflowConditionTest integration tests
sdks/java/src/test/java/org/byteveda/taskito/WorkflowConditionTest.java
Verifies onFailure, always, and callable predicate behavior with execution and node-status assertions.

Sequence Diagram(s)

sequenceDiagram
  participant WorkflowTracker
  participant shouldRun
  participant callableCondition
  participant WorkflowContext
  WorkflowTracker->>shouldRun: evaluate successor condition
  shouldRun->>callableCondition: resolve callable predicate
  callableCondition->>WorkflowContext: buildContext(results, statuses, counts)
  WorkflowContext-->>shouldRun: context
  shouldRun-->>WorkflowTracker: run, skip, or defer
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • ByteVeda/taskito#306: Shares the same Java workflow scheduling and successor/deferred-node machinery that this PR extends for conditional execution.
  • ByteVeda/taskito#331: Also changes DefaultTaskito and WorkflowTracker around workflow control flow and node promotion semantics.

Suggested labels

rust

Poem

🐇 I hopped through conditions, swift and neat,
onFailure, always, callable—so complete!
When nodes decide, the branches glow,
and workflows dance in tidy flow.
A carrot for each passing path 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: conditional workflow steps in the Java SDK.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/java-workflows-conditions

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java`:
- Around line 401-408: The deferred-node detection in deferredNodes() is
treating explicit on_success branches like runtime-evaluated conditions, which
causes default/static paths to be deferred and later depend on WorkflowTracker
and trackWorkflows(...) for job creation. Update the logic so on_success is
normalized back to the default path and excluded from deferred handling, while
keeping fanOut, fanIn, gate, and true conditional branches deferred as before.
Also review the related branch handling around getWorkflowPlan so explicit
on_success does not inherit deferred-job enqueue behavior or queue assumptions.

In `@sdks/java/src/main/java/org/byteveda/taskito/workflows/Step.java`:
- Around line 136-170: Builder.condition(String) currently accepts arbitrary
strings, but WorkflowTracker.shouldRun(...) only understands specific values, so
typos silently fall back to on_success behavior. Update
Step.Builder.condition(String) to validate the input and reject any unknown
condition by throwing an error, while still allowing the known values used by
onSuccess(), onFailure(), always(), and condition(Condition). Keep the fix
localized to the Builder methods so invalid condition strings fail fast instead
of being accepted.

In `@sdks/java/src/main/java/org/byteveda/taskito/workflows/WorkflowTracker.java`:
- Around line 121-126: The fan-out failure path in handleFanOutChild still uses
a blanket cascadeSkipPending(runId), which skips evaluating conditional
successors for the parent. Update handleFanOutChild to follow the same
successor-evaluation flow as onOutcome() by promoting successors through
promoteSuccessors(...) (or equivalent conditional handling) instead of blindly
skipping all pending nodes, so always() and onFailure() branches can still run
after a fan-out child failure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 94808600-1868-4291-9f8d-4ce6f5be0741

📥 Commits

Reviewing files that changed from the base of the PR and between 12f8e38 and 871d32b.

📒 Files selected for processing (7)
  • sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java
  • sdks/java/src/main/java/org/byteveda/taskito/workflows/Condition.java
  • sdks/java/src/main/java/org/byteveda/taskito/workflows/PlanNode.java
  • sdks/java/src/main/java/org/byteveda/taskito/workflows/Step.java
  • sdks/java/src/main/java/org/byteveda/taskito/workflows/WorkflowContext.java
  • sdks/java/src/main/java/org/byteveda/taskito/workflows/WorkflowTracker.java
  • sdks/java/src/test/java/org/byteveda/taskito/WorkflowConditionTest.java

Comment thread sdks/java/src/main/java/org/byteveda/taskito/DefaultTaskito.java Outdated
Comment thread sdks/java/src/main/java/org/byteveda/taskito/workflows/Step.java
@pratyush618
pratyush618 merged commit 7b26819 into master Jun 30, 2026
19 checks passed
@pratyush618
pratyush618 deleted the feat/java-workflows-conditions branch June 30, 2026 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant